package com.hfkh.keyun.controller.backend;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hfkh.keyun.common.ApiResult;
import com.hfkh.keyun.entity.Resource;
import com.hfkh.keyun.exception.BusinessException;
import com.hfkh.keyun.service.ResourceService;
import com.hfkh.keyun.vo.ResourceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @Author: jhh
 */
@RestController
@RequestMapping("/api/resource")
@Api(tags = "资源管理")
public class ResourceController {
    @Autowired
    public ResourceService resourceService;
    @GetMapping("/queryPage")
    @ApiOperation("按专业id查询资源列表并分页")
    public ApiResult queryPage(Integer page,
                               Integer limit,
                               Integer majorId) {
        Page<Resource> pageInfo = new Page<>(page, limit);
        Page<Resource> resourcePage = resourceService.selectResourcePage(pageInfo, majorId);
        return ApiResult.success(resourcePage);
    }
    @PostMapping("/updateResource")
    @ApiOperation(value = "修改资源")
    public ApiResult updateResource(Integer id,ResourceVO resourceVO) throws IOException, BusinessException {
        return resourceService.AddSumUpdResource(resourceVO);
    }

}
